package org.cresource.pet.controller;

import org.cresource.basic.util.AjaxResult;
import org.cresource.basic.util.LoginContext;
import org.cresource.basic.util.PageList;
import org.cresource.pet.domain.Pet;
import org.cresource.pet.domain.SearchMasterMsg;
import org.cresource.pet.query.SearchMasterMsgQuery;
import org.cresource.pet.service.ISearchMasterMsgService;
import org.cresource.user.domain.LoginInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/seachMasterMsg")
public class SearchMasterMsgController {
    @Autowired
    private ISearchMasterMsgService seachMasterMsgService;
   //发布寻主消息
   //发布寻主消息
   //发布寻主消息
    @PostMapping("/publish")
    public AjaxResult publish(@RequestBody SearchMasterMsg searchMasterMsg, HttpServletRequest request){
        try {

            LoginInfo loginInfo = LoginContext.getLoginInfo(request);
            seachMasterMsgService.publish(searchMasterMsg,loginInfo);
            return AjaxResult.me();
        } catch (Exception e) {
        return AjaxResult.me().setMessage("publish系统错误");
        }
    }
    //未处理消息  后台
    //未处理消息  后台
    //未处理消息  后台
    @PostMapping("/pending")
    public PageList<SearchMasterMsg> pending(@RequestBody SearchMasterMsgQuery query, HttpServletRequest request){
        try {
            LoginInfo loginInfo = LoginContext.getLoginInfo(request);
            Long id = loginInfo.getId();
            return seachMasterMsgService.pending(query,id);
        } catch (Exception e) {
            return null;
        }
    }
    //处理消息
    //处理消息
    //处理消息
    @PutMapping("/handle")
    public AjaxResult handle(@RequestBody Pet pet,HttpServletRequest request){
        LoginInfo loginInfo = LoginContext.getLoginInfo(request);
        Long loginInfoId = loginInfo.getId();
        try {
            seachMasterMsgService.handle(pet,loginInfoId);
            return AjaxResult.me();
        } catch (Exception e) {
            return AjaxResult.me().setMessage("handle系统错误");
        }


    }

















    //已处理消息 后台
    //已处理消息 后台
    //已处理消息 后台
    @PostMapping("/processed")
    public PageList<SearchMasterMsg> detail(@RequestBody SearchMasterMsgQuery query, HttpServletRequest request){
        try {
            LoginInfo loginInfo = LoginContext.getLoginInfo(request);
            Long id = loginInfo.getId();
            return seachMasterMsgService.detail(query,id);
        } catch (Exception e) {
            return null;
        }
    }


















    @GetMapping
    public List<SearchMasterMsg> getAll(){
        return seachMasterMsgService.getAll();
    }
}














